import TeamAPI from '@/repo/api/TeamAPI'

export {universityModule, universityTypes, universityActionTypes}

const universityTypes = {
  SET_UNIVERSITY_ENTERPRISE_LIST: 'SET_UNIVERSITY_ENTERPRISE_LIST'
};

const universityActionTypes = {
  UPDATE_UNIVERSITY_ENTERPRISE_LIST: 'UPDATE_UNIVERSITY_ENTERPRISE_LIST'
};

const universityModule = {
  //保存在全局的模块数据
  state: {
    enterpriseList: [],
  },
  //获取数据
  getters: {
    enterpriseList: (state) => state.enterpriseList || []
  },
  //同步请求，只有这里能修改数据
  mutations: {
    [universityTypes.SET_UNIVERSITY_ENTERPRISE_LIST](state, data) {
      state.enterpriseList = data
    },
  },
  //异步请求
  actions: {
    [universityActionTypes.UPDATE_UNIVERSITY_ENTERPRISE_LIST]({commit, state}, param) {
      return new Promise((resolve, reject) => {
        TeamAPI.getTeamList().then((res) => {
          let dataList = res.responseData.list
          commit(universityTypes.SET_UNIVERSITY_ENTERPRISE_LIST, dataList)
          resolve(dataList)
        }).catch((error) => {
          reject(error)
        })
      })

    }
  },
};
